package com.suray.wcs.service.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.suray.basic.wcs.utils.IBaseEnum;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author shaozn
 */

public enum CodeType implements IBaseEnum<Serializable> {
    /**
     * RES故障码
     */
    RES_ERROR_CODE(1, "穿梭车故障"),

    /**
     * 提升机异常
     */
    LIFTER_ERROR_CODE(2, "提升机故障"),

    /**
     * 驱动器故障
     */
    PLC_NEW(10, "新PLC故障码"),
    /**
     * 驱动器故障
     */
    SINGLE_CONVERY(10, "单体输送线"),

    /**
     * 电池均衡故障
     */
    BATTERY_BALANCE_ERROR(20, "电池均衡故障"),

    /**
     * 子车异常码
     */
    RGV_SON_TYPE(100, "子车异常码"),
    ;
    public static Map<Integer, String> typeMap = new HashMap<Integer, String>();

    static {
        CodeType[] types = CodeType.values();
        for (CodeType type : types) {
            typeMap.put(type.state, type.getDescription());
        }
    }

    @EnumValue
    private final int state;

    private final String description;

    CodeType(int state, String description) {
        this.state = state;
        this.description = description;
    }

    @Override
    public String toString() {
        return description;
    }

    @Override
    public Integer getValue() {
        return state;
    }

    @JsonValue
    public String getDesc() {
        return description;
    }

    public int getState() {
        return state;
    }

    /**
     * int 类型转枚举类型
     *
     * @param state
     * @return
     */
    public static CodeType parseCodeType(int state) {
        CodeType[] codeTypes = CodeType.values();
        for (CodeType codeType : codeTypes) {
            if (codeType.state == state) {
                return codeType;
            }
        }
        throw new IllegalArgumentException("故障码类型参数异常");
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public Integer getVal() {
        // TODO Auto-generated method stub
        return null;
    }
}
